package com.hao.wms.mvc;

import com.hao.wms.domain.Cat;
import com.hao.wms.query.CatQueryObject;
import com.hao.wms.service.ICatService;
import com.hao.wms.util.RequiredPermission;
import com.opensymphony.xwork2.interceptor.annotations.InputConfig;

import java.io.IOException;

public class CatAction extends BaseAction{
	/**
	 * 
	 */
	private ICatService catService;
	
	
	private Cat cat = new Cat();
	
	public Cat getCat() {
		return cat;
	}
	public void setCat(Cat cat) {
		this.cat = cat;
	}
	private CatQueryObject queryObject = new CatQueryObject();
	
	
	public CatQueryObject getQueryObject() {
		return queryObject;
	}
	public void setQueryObject(CatQueryObject queryObject) {
		this.queryObject = queryObject;
	}
	public void setCatService(ICatService catService) {
		this.catService = catService;
	}
	@InputConfig(methodName = "input")
	@RequiredPermission(value="Cat列表")
	public String execute() {
		putContext(PAGERESULT, catService.query(queryObject));
		
		return LIST;
	}
	@RequiredPermission(value="新增/修改Cat")
	public String input() {
		if(cat.getId()!=null) {
			cat = catService.get(cat.getId());
		}
		return INPUT;
	}
	@RequiredPermission(value="修改Cat")
	public String saveOrUpdate() {
		try {
			if(cat.getId()!=null) {
                catService.update(cat);
                addActionMessage("修改成功");
            }else {
                catService.save(cat);
                addActionMessage("保存成功");
            }
		} catch (Exception e) {
			e.printStackTrace();
			addActionError(e.getMessage());
		}
		return SUCCESS;
	}
	public void prepareSave(){
		if(cat.getId()!=null) {
			cat = catService.get(cat.getId());
			
		}
	}
	@RequiredPermission(value="删除Cat")
	public String delete() throws IOException {
		catService.delete(cat);
		putResponseText("删除成功");
		return NONE;
	}
	
	

}
